﻿Public Class Recetas_Ingredientes

    Private Sub Recetas_Ingredientes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'DbcoverDataSet2.Ingrediente' Puede moverla o quitarla según sea necesario.
        Me.IngredienteTableAdapter.Fill(Me.DbcoverDataSet2.Ingrediente)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        idReceta_global = ""
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If CantidadTextBox.Text = "" Then
            MessageBox.Show("Ingrese la cantidad", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.CantidadTextBox.Focus()
        Else
            Dim item As String
            item = Me.NombreTextBox1.Text.Trim + " = " + Me.CantidadTextBox.Text.Trim + " " + Me.UnidadMedidaTextBox.Text.Trim
            Me.ListBox2.Items.Add(item)
            Me.NombreTextBox1.Clear()
            Me.CantidadTextBox.Clear()
            Me.UnidadMedidaTextBox.Clear()
            Me.ListBox1.Focus()
        End If

        
    End Sub

    Private Sub CantidadTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles CantidadTextBox.KeyPress
        'ACEPTA SOLO NUMEROS Y ENTER PASA AL SGTE. FOCO
        If e.KeyChar >= Chr(48) And e.KeyChar <= Chr(57) Or e.KeyChar = Chr(8) Then
            e.Handled = False
        Else
            If e.KeyChar = ChrW(Keys.Enter) Then
                e.Handled = True
                SendKeys.Send("{TAB}")
            Else
                If e.KeyChar < Chr(48) Or e.KeyChar > Chr(57) Then
                    e.Handled = True
                End If
            End If
        End If
    End Sub

    Private Sub CantidadTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CantidadTextBox.TextChanged

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim itemRemove As String
        Dim resultado As String = ""
        Dim x As Integer
        itemRemove = Me.ListBox2.SelectedItem.ToString
        For x = 0 To itemRemove.Length - 1
            If itemRemove.Chars(x) = " " Then
                'Me.ListBox1.Items.Add(resultado)
                Me.ListBox2.Items.Remove(Me.ListBox2.SelectedItem)
            Else
                resultado = resultado & itemRemove.Chars(x)
            End If
        Next
    End Sub

    Private Sub ListBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.Click
        Me.CantidadTextBox.Focus()
    End Sub
End Class